<?php
	class ResumeAction extends BaseAction {
		
		public function __construct(){
			parent::__construct();
		}
		
		public function getarea(){
		$type = $_POST['type'];
		$aid = $_POST['aid'];
		$area  = getarea($type,$aid);
		exit(json_encode($area));
		}
		public function resume(){
			$data['uid'] = $_SESSION['member']['uid'];
			$myresume = D('Resume')->getmyresume();
			$user_info = D('member_info')->where($data)->find();
			$myinfo = D('resume')->where($data)->find();
			if(empty($myinfo['myinfo'])){
				$this->assign('in',1);
			}
			if(empty($myinfo['voice'])){
				$this->assign('voice',1);
			}
			if(empty($myinfo['jingyan'])){
				$this->assign('jingyan',1);
			}
			if($user_info['face'] == NULL or $user_info['face'] == 0){
				$this->assign('face',1);
			}
			$exper = D('exper')->where($data)->select();
			if(empty($exper)){
				$this->assign('ex',1);
			}
			if($user_info['status']==0){
				redirect(U('Resume/resume_01'));
			}else{
				$this->assign('resume',$myresume);
			}
			$this->display();
		}
		public function refresh(){
			$data['uid'] = $_SESSION['member']['uid'];
			$map['ctime'] = time();
			$result = D("member_info")->where($data)->save($map);
			if($result){
				$this->ajaxReturn('','success',1);
			}else{
				$this->ajaxReturn('','error',0);
			}
		}
		
		public function say(){
			$data['uid'] = $_SESSION['member']['uid'];
			$da = D("resume")->where($data)->find();
			if($da['isOpen'] == 1){
				$map['isOpen'] = 0;
			}else{
				$map['isOpen'] = 1;
			}
			
			$result = D("resume")->where($data)->save($map);
			if($result){
				$this->ajaxReturn('','success',1);
			}else{
				$this->ajaxReturn('','error',0);
			}
		}

		public function resume_01(){
			$map['uid'] = $_SESSION['member']['uid'];
			$info = D('member_info')->where($map)->find();
			$sheng = explode("-", $info['shengri']);
			$info['sheng1'] = $sheng[0];
			$info['sheng2'] = $sheng[1];
			$info['sheng3'] = $sheng[2];
			$incity = D('area')->where(array('pid'=>$info['pro']))->select();
			$this->assign('incity',$incity);
			$inarea = D('area')->where(array('pid'=>$info['city']))->select();
			$this->assign('inarea',$inarea);
			$inhcity = D('area')->where(array('pid'=>$info['hpro']))->select();
			$this->assign('inhcity',$inhcity);
			$this->assign('info',$info);
			$xueli = D('education')->select();
			$this->assign('xueli',$xueli);
			$pro = getarea();
			$this->assign('pro',$pro);
			$this->display();
		}
		public function resume_02(){
			$map['uid'] = $_SESSION['member']['uid'];
			$resume = D('resume')->where($map)->find();
			$this->assign('resume',$resume);
			$wtime = D('work_time')->select();
			$this->assign('wtime',$wtime);
			$hangye = D('hangye') ->select();
			foreach($hangye as $k=>&$v){
				$v['posi'] = D('position')->where(array('hid'=>$v['id']))->select();
			}
			$this->assign('hangye',$hangye);
			$this->display();
		}
		public function add_member_info(){
			$data['shengri'] = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
			$data['ctime'] = time();
			$from_keys = array(	'truename', 'xingbie', 'phone', 'shengao',
							'tizhong', 'hunyin', 'xueli', 'pro', 'city',
							'area', 'hpro', 'hcity'
					);
			foreach ($from_keys as $key ) {
				$data[$key] = trim($_POST[$key]);
			}
			$result = D('Resume')->add_member($data);
			$edit = $_POST['edit'];
			if($result){
				if($edit == 1){
					$this->success('修改成功！');	
				}else{
					redirect(U('Resume/resume_02'));
				}
				
			}else{
				$this->success('添加失败！');
			}
		}
		public function add_resume02(){
			$data['jingyan'] = $_POST['jingyan'];
			$string=implode(',',$_POST['work_time']); 
			$data['yx_worktime'] = $string;
			$data['zhuangtai'] = $_POST['zhuangtai'];
			$data['yhyf'] = implode(',',$_POST['yxhy']);
			$data['ctime'] = time();
			$result = D('Resume')->add_resume($data);
			$edit = $_POST['edit'];
			if($result){
				if($edit == 1){
					$this->success('修改成功！');	
				}else{
					redirect(U('Resume/resume_03'));
				}
				
			}else{
				$this->success('添加失败！');
			}
		}
		public function edit_exper_info(){
			$map['in_id'] = $_GET['id'];
			$exper = D('exper')->where($map)->find();
			$begin = explode('-', $exper['jobbegin']);
			$end = explode('-', $exper['jobend']);
			$exper['year'] = $begin[0];
			$exper['month'] = $begin[1];
			$exper['endyear'] = $end[0];
			$exper['endmonth'] = $end[1];
			$this->assign('exper',$exper);
			$this->display();
		}
		public function add_exper_info(){
			$map['in_id'] = $_POST['id'];
			$data['jobbegin'] = $_POST['year']."-".$_POST['month'];
			$data['jobend'] = $_POST['endyear']."-".$_POST['endmonth'];
			$data['jobname'] = $_POST['band'];
			$data['jobzhiwei'] = $_POST['position'];
			$result = D('exper')->where($map)->save($data);
			if($result){
				$this->success('修改成功！');
				redirect(U('Resume/edit_exper'));
			}
		}
		public function edit_exper(){
			$map['uid'] = $_SESSION['member']['uid'];
			$map['is_del'] = 0;
			$exper = D('exper')->where($map)->select();
			$this->assign('exper',$exper);
			$this->display();
		}
		public function del_exper(){
			$data['in_id'] = $_POST['info_id'];
			$map['is_del'] = 1;
			$result = D('exper')->where($data)->save($map);
			if($result){
				$this->ajaxReturn('','success',1);
			}else{
				$this->ajaxReturn('','error',0);
			}
		}
		public function add_exper(){
			$data = array();
			$tmp  = array_values($_POST['from']);
			$max = count($tmp[0]);
			for($i=0; $i< $max; $i++){
				$data[$i]['jobname']	= $_POST['from']['band'][$i];
				$data[$i]['jobzhiwei']	= $_POST['from']['position'][$i];
				$data[$i]['jobbegin']	= $_POST['from']['year'][$i] . '-' . $_POST['from']['month'][$i];
				$data[$i]['jobend']		= $_POST['from']['endyear'][$i] . '-' . $_POST['from']['endmonth'][$i];
				$data[$i]['ctime']		= time();
				$data[$i]['uid']		= $_SESSION['member']['uid'];
				$result = D('exper')->add($data[$i]);
			}
			
			if($result == true){
				redirect(U('Resume/resume_04'));
			}else{
				$this->success('添加失败！');
			}
			
		}
		public function resume_04(){
			$map['uid'] = $_SESSION['member']['uid'];
			$resume = D('resume')->where($map)->find();
			$this->assign('info',$resume['myinfo']);
			$this->display();
		}
		public function add_myinfo(){
			$data['myinfo'] = $_POST['introduce'];
			$data['ctime'] = time();
			$result = D('Resume')->add_resume($data);
			$edit = $_POST['edit'];
			$url = U('Resume/resume');
			if($result){
				if($edit == 1){
					$this->success('修改成功！',$url);	
				}else{
					/*redirect(U('Resume/get_prize'));*/
					redirect(U('Resume/wan'));
				}
			}else{
				$this->success('添加失败！');
			}
		}
		
		public function wan(){
			$data['uid'] = $_SESSION['member']['uid'];
			$myresume = D('Resume')->getmyresume();
			$user_info = D('member_info')->where($data)->find();
			$myinfo = D('resume')->where($data)->find();
			if(empty($myinfo['myinfo'])){
				$this->assign('in',1);
				$wan = 0;
			}else{
				$wan = 1;
			}
			if(empty($myinfo['voice'])){
				$this->assign('voice',1);
				$wan = 0;
			}else{
				$wan = 1;
			}
			if(empty($myinfo['jingyan'])){
				$this->assign('jingyan',1);
				$wan = 0;
			}else{
				$wan = 1;
			}
			if($user_info['face'] == NULL or $user_info['face'] == 0){
				$this->assign('face',1);
				$wan = 0;
			}else{
				$wan = 1;
			}
			$exper = D('exper')->where($data)->select();
			if(empty($exper)){
				$this->assign('ex',1);
				$wan = 0;
			}else{
				$wan = 1;
			}
			if($user_info['status']==0){
				redirect(U('Resume/resume_01'));
			}else{
			}
			$this->assign('wan',$wan);
			$this->display();
		}

		public function delimg(){
			$imgid = $_POST['imgid'];
			if(D('Resume')->delimg($imgid)){
				foreach($_SESSION['resumestep'][6] as $k => $v){
					if($v['imgid'] == $imgid){
						unset($_SESSION['resumestep'][6][$k]);
					}
				}
				$return = array('status'=>1,'data'=>'删除成功');
			}else{
				$return = array('status'=>0,'data'=>'删除失败');
			}
			exit(json_encode($return));
		}
		
		public function getvoiceurl(){
			$mp3url = getvoice($_GET['voice']);
			header('Content-type: audio/mp3');  
			header('Content-Disposition: attachment; filename="'.rand(1000000,9999999).'.mp3"');  
			readfile($mp3url);  
		}
		public function get_prize(){
			$map['uid'] = $_SESSION['member']['uid'];
			$map['is_del'] = 0;
			$info = D('member_info')->where($map)->find();
			if($info['is_prize'] == 1){
				$this->assign('prize',"1");
			}else{
				$this->assign('phone',$info['phone']);
			}
			$this->display();
		}
		public function send_prize(){
			//if($_POST['yzcode']==$_SESSION['yzcode'][$_POST['phone']]['code']&&(time()-$_SESSION['yzcode'][$_POST['phone']]['ctime'])<=1800){
				$money = 5;
				$phone = $_POST['phone'];
				$userid= "A1021937";
				$userpws="199007298ba69f00df9dbde94be66410";
				$url = "http://api2.ofpay.com";
				$url1=$url."/telquery.do?userid=".$userid."&userpws=".$userpws."&phoneno=".$phone."&pervalue=".$money."&version=6.0";
				$xml = file_get_contents($url1);
				$xml = simplexml_load_string($xml);
				$retcode= $xml->retcode;
				$cardid= $xml->cardid;
				if($retcode == 1){
					$sporder_time = date("YmdHis",time());
					$sporder_id = 's'.$sporder_time.time();
					$KeyStr = "OFCARD";
					$md = $userid.$userpws.$cardid.$money.$sporder_id.$sporder_time.$phone.$KeyStr;
					$md = md5($md);
					$md5_str = strtoupper($md); 
					$url2 = $url."/onlineorder.do?userid=".$userid."&userpws=".$userpws."&cardid=".$cardid."&cardnum=".$money."&sporder_id=".$sporder_id."&sporder_time=".$sporder_time."&game_userid=".$phone."&md5_str=".$md5_str."&ret_url=&version=6.0";
					$xml2 = file_get_contents($url2);
					$xml2 = simplexml_load_string($xml2);
					$retcode2= $xml2->retcode;
					if($retcode2 == 1){
						$map['uid'] = $_SESSION['member']['uid'];
						$info = D('member_info')->where($map)->save(array('is_prize'=>1));
						if($info){
							$url3 = U('Resume/share_prize');
							$this->success('充值成功',$url3);
						}
					}
				}
			//}else{
				//$this->error('验证码不对的');
			//}
			
		}
		public function share_prize(){
			$this->display();
		}
		public function yzcode(){
			if((time()-$_SESSION['yzcode'][$_POST['phone']]['ctime'])>1800){
				$_SESSION['yzcode'][$_POST['phone']] = array('code' => rand(100000,999999),'ctime'=>time());
			}
			$msg = '您验证码为：'.$_SESSION['yzcode'][$_POST['phone']]['code'].'。【人才来了】';
			$result = $this->SendMesg($msg,$_POST['phone']);
			if($result){
				$return = array('status'=>1,'data'=>'短信发送成功，记得把验证码发到');
			}else{
				$return = array('status'=>0,'data'=>'短信发送失败，请重新确认手机号码');
			}
			exit(json_encode($return));
		}

		public function SendMesg($con,$num){
			require_once 'HttpClient.class.php';
			$client = new HttpClient ("www.lx198.com");
			if (! $client->post ( '/sdk/send', array (
					'accName' => "18621771369",
					'accPwd' => strtoupper ( md5 ( "dd200412" ) ),
					'bizId' => date ( 'YmdHis' ),
					'content' => mb_convert_encoding ( $con, 'UTF-8', 'UTF-8' ),
					'aimcodes' =>$num ,
					'dataType'=>"xml"
			) )) {
				return false;
			} else {
				$xmlStr = $client->getContent () ;
				$doc = new DOMDocument ();
				$doc->loadXML ( $xmlStr );
				$xml = simplexml_load_string($xmlStr);
				if($xml->replyCode == 1){
					return true;
				}else{
					return false;
				}
			}
		}


			public function reply_other(){
				import('ORG.Mailer.Mail');
				$uid = $_POST['uid'];
				$data['uid'] = $uid;
				$info = D('member_info')->where('uid = '.$uid)->find();
				$data['info_id'] = $info['info_id'];
				if($_POST['phone'] !=""){
					$data['phone'] = $_POST['phone'];
				}
				if($_POST['mail'] !=""){
					$data['mail'] = $_POST['mail'];
				}
				$data['ctime'] = time();
				$send = D('send')->add($data);
				$id = mysql_insert_id();
				$url = "http://www.rencailaile.com/weixin.php?s=/Companycontrol/resume_one/uid/".$uid."/sid/".$id;
				$url = $this->short_url($url);
				if($_POST['phone'] !=""){
					$msg = $info['truename'].'向您发送了一封简历，请点击查看：'.$url.'。【人才来了】';
					$result = $this->SendMesg($msg,$_POST['phone']);
				}
				if($_POST['mail'] !=""){
						$Mail = A("Mail");
						$Mail->sendMail($_POST['mail'],$truename,$url);
						$result = true;
				}
				if($result){
					$this->success('推荐成功');
				}else{
					$this->error('推荐失败');
				}
			}
		
		
	
	public function short_url($url){
		$key = '1562966081'; 
   		$baseurl = 'http://api.t.sina.com.cn/short_url/shorten.json?source='.$key.'&url_long='.$url; 
   		$ch=curl_init(); 
	    curl_setopt($ch, CURLOPT_URL,$baseurl); 
	    curl_setopt($ch, CURLOPT_HEADER, 0); 
	    curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
	    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
	    $strRes=curl_exec($ch); 
	    curl_close($ch); 
	    $arrResponse=json_decode($strRes,true); 
	    if (isset($arrResponse->error) || !isset($arrResponse[0]['url_long']) || $arrResponse[0]['url_long'] == ''){
	    	return 0; 
	    } 
    	return $arrResponse[0]['url_short']; 
   
    }


	}
?>